package com.nowcoder.Offer.Math;

import org.junit.Test;

/**
 * 丑数
 */
public class UglyNumber {

    public int GetUglyNumber_Solution(int index) {
        int a = 0, b = 0, c = 0;
        int[] dp = new int[index + 1];
        dp[0] = 1;
        for(int i=1; i<index; i++){
            int n2 = dp[a] * 2;
            int n3 = dp[b] * 3;
            int n5 = dp[c] * 5;
            dp[i] = Math.min(Math.min(n2,n3),n5);
            if(dp[i] == n2) a++;
            if(dp[i] == n3) b++;
            if(dp[i] == n5) c++;
        }
        return dp[index - 1];
    }


    @Test
    public void test(){
        System.out.println(GetUglyNumber_Solution(10));
    }

}
